package com.zhilianbao.leyaogo.ui.adapter.home.applista;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zhilianbao.leyaogo.R;
import com.zhilianbao.leyaogo.utils.Utils;

import me.drakeet.multitype.ItemViewProvider;

/**
 * 首页更多TypeViewProvider
 */
public class HomeTopicMoreViewProvider
        extends ItemViewProvider<HomeTopicMore, HomeTopicMoreViewProvider.ViewHolder> {

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(
            @NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_home_topic_more, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull HomeTopicMore homeTopicMore) {
        holder.mLlMore.setOnClickListener(v -> {
            switch (homeTopicMore.getType()) {
                //跳转到商品列表
                case 1:
                    Utils.startGoodsClassifyList((Activity) holder.mLlMore.getContext(), homeTopicMore.getId(), homeTopicMore.getTitle());
                    break;
                //跳转到专题活动详情
                case 2:
                case 3:
                    Utils.startActivityDetails((Activity) holder.mLlMore.getContext(), homeTopicMore.getId(), false);
                    break;
            }
        });
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        private TextView mTvMore;
        private LinearLayout mLlMore;

        ViewHolder(View itemView) {
            super(itemView);
            mTvMore = (TextView) itemView.findViewById(R.id.tv_topic_more);
            mLlMore = (LinearLayout) itemView.findViewById(R.id.ll_more);
        }
    }
}